package com.sdwl.brcl.validation.validation;

import com.sdwl.brcl.validation.enums.EnumAware;
import org.apache.commons.lang3.StringUtils;

/**
 * @author xied
 * @date 2021年06月11日 14:09
 */
public class ValidatorElement {
    private Validator validator;
    private Object validateValue;
    private String validateName;
    private String errorCode;
    private String errorMsg;

    public ValidatorElement(Object validateValue, String validateName, Validator validator) {
        this.validateValue = validateValue;
        this.validateName = validateName;
        this.validator = validator;
    }

    public ValidatorElement(Object validateValue, EnumAware enumAware, Validator validator) {
        this.validateValue = validateValue;
        this.errorCode = enumAware.getCode();
        this.errorMsg = enumAware.getName();
        this.validator = validator;
    }

    public String getErrorCode() {
        if (StringUtils.isBlank(this.errorCode)) {
            this.errorCode = this.validator.validateCode();
        }

        return this.errorCode;
    }

    public String getErrorMsg() {
        if (StringUtils.isBlank(this.errorMsg)) {
            this.errorMsg = this.validator.validateMsg(this.validateValue, this.validateName);
        }

        return this.errorMsg;
    }

    public Validator getValidator() {
        return this.validator;
    }

    public void setValidator(Validator validator) {
        this.validator = validator;
    }

    public Object getValidateValue() {
        return this.validateValue;
    }

    public void setValidateValue(Object validateValue) {
        this.validateValue = validateValue;
    }

    public String getValidateName() {
        return this.validateName;
    }

    public void setValidateName(String validateName) {
        this.validateName = validateName;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }
}
